package com.ruoyi.bigScreen;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.zzw.TIndicatorsInfo;
import com.ruoyi.common.core.domain.zzw.TRegionInfo;
import com.ruoyi.common.core.domain.zzw.VO.TIndicatorsList;
import com.ruoyi.system.service.ITIndicatorsInfoService;
import com.ruoyi.system.service.ITRegionInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;

/**
 * 指标Controller
 *
 * @author xbx
 * @date 2023-10-20
 */

@Api(tags = "指标管理")
@RestController
@RequestMapping("/screen/indicators")
public class ScreenTIndicatorsInfoController extends BaseController {

    @Autowired
    private ITIndicatorsInfoService tIndicatorsInfoService;
    @Autowired
    private ITRegionInfoService regionInfoService;

    @ApiOperation("通过模块查询指标列表")
    @GetMapping(value = "/listByModule")
    public AjaxResult listByModuleAndDistrict(@Valid @NotBlank(message = "目录ID不能为空") String moduleId, String areaCode) {
        String districtId = "1";
        if (StringUtils.isNotBlank(areaCode) && !"100000".equals(areaCode)){
            TRegionInfo info = regionInfoService.getByAreaCode(areaCode);
            if (null == info){
                return success(new ArrayList<>());
            }
            districtId = info.getCRegionId().toString();
        }
        List<TIndicatorsList> list = tIndicatorsInfoService.listByModuleAndDistrict(moduleId, districtId);
        return success(list);
    }

    @ApiOperation("通过所属地区查询指标详")
    @GetMapping(value = "/listByDistrict")
    public AjaxResult listByDistrict(String districtId) {
        return success(tIndicatorsInfoService.listByCDistrictId(districtId));
    }

    @ApiOperation("查询指标关联的事件")
    @GetMapping(value = "/listRelatedEvent")
    public AjaxResult getRelatedEvent(String indicatorsId) {
        return success(tIndicatorsInfoService.getRelatedEvent(indicatorsId));
    }

    @ApiOperation("ID查询指标")
    @GetMapping(value = "/get")
    public AjaxResult listBySafenessId(Long indicatorsId) {
        return success(tIndicatorsInfoService.getByIndicatorsId(indicatorsId));
    }
}
